local LB_U = require "packages.lb_kill_utility.utility"

local skel = fk.CreateSkill {
  name = "lb_zero__canshan",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lb_zero__canshan"] = "璨闪",
  [":lb_zero__canshan"] = "<b>锁定技</b>，你须以将之翻面的方式使用面置的基本牌或普通锦囊牌。",

  ["$lb_zero__canshan1"] = "我们很有共鸣呢。",
  ["$lb_zero__canshan2"] = "演出要开始了吗？",
}

skel:addEffect(fk.PreCardUse, { -- 还是用这个版本吧
  priority = 2,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
      if #data.card.subcards > 0 then
        return table.find(data.card.subcards, function(id)
          return not LB_U.isBackCards(Fk:getCardById(id)) and table.contains(player:getCardIds("h"), id)
        end)
      else
        return not (data.card:isVirtual() or LB_U.isBackCards(data.card)) and table.contains(player:getCardIds("h"), data.card.id)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if #data.card.subcards == 0 then
      local cid = data.card.id
      local card = Fk:cloneCard(data.card.name, data.card.suit, data.card.number)
      for k, v in pairs(data.card) do
        if card[k] == nil then
          card[k] = v
        end
      end
      card.skillNames = data.card.skillNames
      table.insertIfNeed(card.skillNames, skel.name)
      data.card = card
      LB_U.backCards(player, cid)
    else
      for _, id in ipairs(data.card.subcards) do
        local card = Fk:getCardById(id)
        if not LB_U.isBackCards(card) and table.contains(player:getCardIds("h"), id) then
          LB_U.backCards(player, id)
        end
      end
      data.card.subcards = {}
    end
  end,
})

--[[
skel:addEffect(fk.BeforeCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      for _, move in ipairs(data) do
        if move.from == player and move.moveReason == fk.ReasonUse then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if card.type == Card.TypeBasic or card:isCommonTrick() then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = {}
    for _, move in ipairs(data) do
      if move.from == player and move.moveReason == fk.ReasonUse then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card.type == Card.TypeBasic or card:isCommonTrick() then
            table.insert(ids, info.cardId)
          end
        end
      end
    end
    if #ids > 0 then
      LB_U.backCards(player, ids)
      player.room:cancelMove(data, ids)
    end
  end,
})
--]]
return skel
